<?php 
/**
 * 品牌控制器
 */
class BrandController extends AuthController{
	// 模型属性
	private $db;
	// 品牌缓存
	private $brand;
	// 品牌主键ID
	private $bid;
	// 构造函数
	public function __init(){
		$this->db=K('Brand');
		$this->brand=S('brand');
		$this->bid=Q('bid','0','intval');
	}
	public function index(){
			$data=$this->db->order('brand_order desc')->all();
			$this->assign('data',$data);
			$this->display();
	}
	/**
	 *添加品牌
	 */
	public function add(){
		if (IS_POST){
			if($this->db->addBrand()){
				$this->success('添加品牌成功','Index');
			}else{
				$this->error($this->db->error);
			}
		}else{
			$this->display();
		}
	}
// 编辑品牌
 	public function edit(){
 		if(IS_POST){
 			if($this->db->editBrand()){
 				$this->success('修改品牌成功','index');
 			}else{
 				$this->error($this->db->error);
 			}
 		}else{
 			$data=$this->db->find($this->bid);
 			$data['brand_logo']=array(array('path'=>$data['brand_logo']));
 			$this->assign('brand',$data);
 			$this->display();
 		}
 	}

 	//删除品牌
 	public function del(){
 		if($this->db->delBrand($this->bid)){
 			$this->success('删除成功','index');
 		}else{
 			$this->error($this->db->error);
 		}
 	}

 }//品牌控制器类结束



